#include <iostream>
#include<cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1e5 + 100;
long dp[N][2];
int row[N][2];
int main()
{
	memset(row, -1, sizeof row);
	int n, m;
	scanf("%d%d", &n, &m);
 
	for (int i = 1; i <= m; i++)
	{
		int x, y;
		 scanf("%d%d", &x, &y);
 
		if (row[y][0]==-1)
			row[y][0] = x;
		else
			row[y][0] = min(row[y][0], x);
		row[y][1] = max(row[y][1], x);
	}
 
	//动态规划
	if (row[0][1] != -1)
	{
		dp[0][0] = dp[0][1] = row[0][1];
		row[0][0] = row[0][1];
	}
	else 	row[0][0]=row[0][1]=0;
	for (int i = 1; i <= n; i++)
	{
		if (row[i][0] == -1 && row[i][1] == -1)
		{
			dp[i][0] = dp[i - 1][0] + 1;
			dp[i][1] = dp[i - 1][1] + 1;
			row[i][0] = row[i - 1][0];
			row[i][1] = row[i - 1][1];
		}
		else
		{
			dp[i][0] = min(dp[i - 1][0] + abs(row[i][1] - row[i - 1][0]) + row[i][1] - row[i][0] + 1, dp[i - 1][1] + abs(row[i][1] - row[i - 1][1]) + row[i][1] - row[i][0] + 1);
			dp[i][1] = min(dp[i - 1][0] + abs(row[i][0] - row[i - 1][0]) + row[i][1] - row[i][0] + 1, dp[i - 1][1] + abs(row[i][0] - row[i - 1][1]) + row[i][1] - row[i][0] + 1);
		}
	}
	cout << min(dp[n][0] + n - row[n][0], dp[n][1] + n - row[n][1]);
	return 0;
}